package com.jblog.controller.front.action.blog;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jblog.controller.front.action.BaseAct;
import com.jblog.core.model.blog.archive.PostCalendarArchive;

@Controller
@RequestMapping("/archive")
public class ArchiveAct extends BaseAct {

    @RequestMapping(method = RequestMethod.GET)
    public String index(HttpServletRequest request, ModelMap model) {
        return "forward:/";
    }

    @RequestMapping(value = "/calendar/post/{year}", method = RequestMethod.GET)
    public String calendarPostYear(HttpServletRequest request, ModelMap model,
            @PathVariable String year) {
        PostCalendarArchive archive = new PostCalendarArchive(year);
        model.put("archiveCalendarPost", archive);
        
        return F(request, model, "blog/main");
    }

    @RequestMapping(value = "/calendar/post/{year}/{month}", method = RequestMethod.GET)
    public String calendarPostYearMonth(HttpServletRequest request,
            ModelMap model, @PathVariable String year, @PathVariable String month) {
        PostCalendarArchive archive = new PostCalendarArchive(year, month);
        model.put("archiveCalendarPost", archive);
        
        return F(request, model, "blog/main");
    }

}
